package com.cn.wanxi.util.service;

import com.cn.wanxi.util.dao.CompanyDao;
import com.cn.wanxi.util.dao.NavDao;
import com.cn.wanxi.util.model.CompanyModel;
import com.cn.wanxi.util.util.IOTool;
import com.cn.wanxi.util.util.MyPath;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 封装数据逻辑
 */
public class CompanyService {


    /**
     * 1.公司信息应该来源于记事本（文件）
     * 2.创建文件---》创建文件夹
     * 3.写入数据
     * 4.读取数据
     * 5.封装对象
     */
    public CompanyModel getCompanyModel() {
//        1.创建文件---》创建文件夹
//        引用传递和值传递

//        IOTool.createNote(fileName);
//        2.写入数据
        IOTool.writeNote(MyPath.FILE_COMPANY.getPath(), getCompanyModelData());
//        3.读取数据
        String result = IOTool.readNote();
//        4.封装数据
        return setCompanyModelData(result);
    }

    private List<String> getCompanyModelData() {
        List<String> list = new ArrayList<>();
        CompanyDao companyDao = new CompanyDao();
        list.add(companyDao.getLogo());
        list.add(companyDao.getPhone());
        list.add(companyDao.getNet());
        list.add(companyDao.getEmail());
        list.add(companyDao.getAddress());
        list.add(companyDao.getVersion());
        list.add(companyDao.getLinePhone());
        return list;
    }

    private CompanyModel setCompanyModelData(String result) {
//substring截取字符串的某一段字符
        String[] strings = result.split(MyPath.SPLIT.getPath());
//        for (String aa:strings
//             ) {
//            System.out.println(aa);
//        }
        CompanyModel companyModel = new CompanyModel();
        companyModel.setLogo(strings[0]);
        companyModel.setPhone(strings[1]);
        companyModel.setNet(strings[2]);
        companyModel.setEmail(strings[3]);
        companyModel.setAddress(strings[4]);
        companyModel.setVersion(strings[5]);
        companyModel.setLinePhone(strings[6]);
        return companyModel;
    }


    public static void main(String[] args) {
        new CompanyService().getCompanyModel();
    }


}
